<?php

/**
 * PaymentChecks form.
 *
 * @package    erp-crm
 * @subpackage form
 * @author     Milwell H. Sia
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class PaymentChecksForm extends BasePaymentChecksForm
{
  public function configure()
  {
    if($this->isNew()){
      $this->validatorSchema['payment_iden'] = new sfValidatorString(array('required' => true));
      $this->validatorSchema['check_iden'] = new sfValidatorString(array('required' => true));
      $this->setDefault('check_amount',0);
    }
    
    $this->validatorSchema['check_amount']->setOption('min',0.01);
     
    $this->widgetSchema->setLabels(
      array(
        'bank_initials'=>'Bank',
        'account_number'=>'Account#',
        'check_number'=>'Check#',
        'check_date'=>'Date',
        'check_amount'=>'Amount',
      )
    );
    
    $this->validatorSchema->setPostValidator(
      new sfValidatorCallback(
        array(
          'callback'=>array(
            $this,'validateCheck',
          ),
        )
      )
   );
    
  }
  
  
  public function validateCheck($validator,$values){
    $check_data_status = '00000';
    if($values['bank_initials'])
      $check_data_status[0] = '1';
    if($values['account_number'])
      $check_data_status[1] = '1';
    if($values['check_number'])
      $check_data_status[2] = '1';
    if($values['check_date'])
      $check_data_status[3] = '1';
    if($values['check_amount']>0)
      $check_data_status[4] = '1';
    if (($check_data_status != '00000')&&($check_data_status != '11111')){
      $error['global_check_error'] = new sfValidatorError($validator,'Check data incomplete');
      throw new sfValidatorErrorSchema($validator,$error);
    }
    return $values;
  }
  
  
}
